home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tde210.zip / CFGMODES.C < prev    next >
C/C++ Source or Header  |  1992-11-13  |  14KB  |  598 lines

  1. /*
  2.  * Author:        Frank Davis
  3.  * Date:          January 20, 1992
  4.  * Compiler:      MSC 6.0a and QuickC 2.5
  5.  *
  6.  * This program is released into the public domain.  You may distribute
  7.  * it freely, Frank Davis
  8.  */
  9.  
  10.  
  11. /********    EXTREMELY IMPORTANT   ************/
  12. /*
  13.  * If you modify tde, it is your responsibility to find the offset of
  14.  * "mode_infos mode", a global structure declared in ed.c.
  15.  *
  16.  * If you don't change the default modes, search for the following string,
  17.  * a hexadecimal integer array, in your new executable file:
  18.  *
  19.  *  0000 0000 0100 0100 0100 0800 0000 0000
  20.  *
  21.  * Then, replace MODE_OFFSET with your new one and recompile tdecfg
  22.  * with the new offset.
  23.  */
  24. /*******     EXTREMELY IMPORTANT   ************/
  25.  
  26.  
  27. #include <bios.h>
  28. #include <dos.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "tdecfg.h"
  34. #include "cfgmodes.h"
  35.  
  36.  
  37. extern struct vcfg cfg;         /* video stuff */
  38. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  39.  
  40. MODE_INFO in_modes;           /* play around with modes in this struct */
  41.  
  42. int color;
  43.  
  44. /*
  45.  * Name:    tdemodes
  46.  * Date:    July 21, 1991
  47.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  48.  *          variables  2) show the user a color sample  3) make the changes
  49.  *          permanent if desired.
  50.  */
  51. void tdemodes( void )
  52. {
  53.    color = 7;
  54.    initialize_modes( );
  55.    show_init_mode( );
  56.    change_modes( );
  57. }
  58.  
  59.  
  60. /*
  61.  * Name:    initialize_modes
  62.  * Date:    July 21, 1991
  63.  * Notes:   Set up the global mode variables.
  64.  */
  65. void initialize_modes( void )
  66. {
  67. int i, j;
  68.  
  69.    fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  70.    fread( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  71.  
  72.    mode[Ins].mode      = in_modes.insert;
  73.    mode[Ind].mode      = in_modes.indent;
  74.    mode[PTAB].mode     = in_modes.ptab_size;
  75.    mode[LTAB].mode     = in_modes.ltab_size;
  76.    mode[Smart].mode    = in_modes.smart_tab;
  77.    mode[Write_Z].mode  = in_modes.control_z;
  78.    mode[Crlf].mode     = in_modes.crlf;
  79.    mode[Trim].mode     = in_modes.trailing;
  80.    mode[Eol].mode      = in_modes.show_eol;
  81.    mode[WW].mode       = in_modes.word_wrap;
  82.    mode[Left].mode     = in_modes.left_margin;
  83.    mode[Para].mode     = in_modes.parg_margin;
  84.    mode[Right].mode    = in_modes.right_margin;
  85.    mode[Size].mode     = in_modes.cursor_size;
  86.    mode[Backup].mode   = in_modes.do_backups;
  87.    mode[Ruler].mode    = in_modes.ruler;
  88.    mode[Date].mode     = in_modes.date_style;
  89.    mode[Time].mode     = in_modes.time_style;
  90.    mode[Initcase].mode = in_modes.search_case;
  91. }
  92.  
  93.  
  94. /*
  95.  * Name:    show_init_mode
  96.  * Date:    July 21, 1991
  97.  * Notes:   Draw the sample screen.
  98.  */
  99. void show_init_mode( void )
  100. {
  101. char *sample;
  102. int line, i;
  103.  
  104.    cls( );
  105.    xygoto( -1, -1 );
  106.    for (i=0,line=1; sample != NULL; line++, i++) {
  107.       sample = mode_screen[i];
  108.       s_output( (char far *)sample, line, 0, 7 );
  109.    }
  110.    for (i=0; i<19; i++)
  111.       (*mode[i].show_me)();
  112. }
  113.  
  114.  
  115. /*
  116.  * Name:    show_insert_mode
  117.  * Date:    January 20, 1992
  118.  */
  119. void show_insert_mode( void )
  120. {
  121. char *p[] = {
  122.    "Overwrite",
  123.    "Insert   "
  124. };
  125.  
  126.    s_output( p[mode[Ins].mode], mode[Ins].line, mode[Ins].col, color );
  127. }
  128.  
  129.  
  130. /*
  131.  * Name:    show_indent_mode
  132.  * Date:    January 20, 1992
  133.  */
  134. void show_indent_mode( void )
  135. {
  136. char *p[] = {
  137.    "Indent off",
  138.    "Indent on "
  139. };
  140.  
  141.    s_output( p[mode[Ind].mode], mode[Ind].line, mode[Ind].col, color );
  142. }
  143.  
  144.  
  145. /*
  146.  * Name:    show_ptabsize
  147.  * Date:    January 20, 1992
  148.  */
  149. void show_ptabsize( void )
  150. {
  151. char temp[10];
  152.  
  153.    s_output( "   ", mode[PTAB].line, mode[PTAB].col, color );
  154.    s_output( itoa(mode[PTAB].mode,temp,10), mode[PTAB].line, mode[PTAB].col,color);
  155. }
  156.  
  157.  
  158. /*
  159.  * Name:    show_ltabsize
  160.  * Date:    January 20, 1992
  161.  */
  162. void show_ltabsize( void )
  163. {
  164. char temp[10];
  165.  
  166.    s_output( "   ", mode[LTAB].line, mode[LTAB].col, color );
  167.    s_output( itoa(mode[LTAB].mode,temp,10), mode[LTAB].line, mode[LTAB].col,color);
  168. }
  169.  
  170.  
  171. /*
  172.  * Name:    show_controlz
  173.  * Date:    January 20, 1992
  174.  */
  175. void show_controlz( void )
  176. {
  177. char *p[] = {
  178.    "Write ^Z",
  179.    "No ^Z   ",
  180. };
  181.  
  182.    s_output( p[mode[Write_Z].mode], mode[Write_Z].line,mode[Write_Z].col,color);
  183. }
  184.  
  185.  
  186. /*
  187.  * Name:    show_eol_out
  188.  * Date:    January 20, 1992
  189.  */
  190. void show_eol_out( void )
  191. {
  192. char *p[] = {
  193.    "",
  194.    "CRLF",
  195.    "LF  ",
  196. };
  197.  
  198.    s_output( p[mode[Crlf].mode], mode[Crlf].line, mode[Crlf].col, color );
  199. }
  200.  
  201.  
  202. /*
  203.  * Name:    show_trail
  204.  * Date:    January 20, 1992
  205.  */
  206. void show_trail( void )
  207. {
  208. char *p[] = {
  209.    "No Trim",
  210.    "Trim   ",
  211. };
  212.  
  213.    s_output( p[mode[Trim].mode], mode[Trim].line, mode[Trim].col, color );
  214. }
  215.  
  216.  
  217. /*
  218.  * Name:    show_eol_display
  219.  * Date:    January 20, 1992
  220.  */
  221. void show_eol_display( void )
  222. {
  223. char *p[] = {
  224.    "Off",
  225.    "On ",
  226. };
  227.  
  228.    s_output( p[mode[Eol].mode], mode[Eol].line, mode[Eol].col, color );
  229. }
  230.  
  231.  
  232. /*
  233.  * Name:    show_smart_mode
  234.  * Date:    January 20, 1992
  235.  */
  236. void show_smart_mode( void )
  237. {
  238. char *p[] = {
  239.    "Off",
  240.    "On ",
  241. };
  242.  
  243.    s_output( p[mode[Smart].mode], mode[Smart].line, mode[Smart].col, color );
  244. }
  245.  
  246.  
  247. /*
  248.  * Name:    show_ww
  249.  * Date:    January 20, 1992
  250.  */
  251. void show_ww( void )
  252. {
  253. char *p[] = {
  254.    "Off                ",
  255.    "Fixed margins      ",
  256.    "Dynamic left margin",
  257. };
  258.  
  259.    s_output( p[mode[WW].mode], mode[WW].line, mode[WW].col, color );
  260. }
  261.  
  262.  
  263. /*
  264.  * Name:    show_initcase
  265.  * Date:    January 20, 1992
  266.  */
  267. void show_initcase( void )
  268. {
  269. char *p[] = {
  270.    "      ",
  271.    "IGNORE",
  272.    "MATCH ",
  273. };
  274.  
  275.    s_output( p[mode[Initcase].mode], mode[Initcase].line, mode[Initcase].col,
  276.               color );
  277. }
  278.  
  279.  
  280. /*
  281.  * Name:    show_left
  282.  * Date:    January 20, 1992
  283.  */
  284. void show_left( void )
  285. {
  286. char temp[10];
  287.  
  288.    s_output( "   ", mode[Left].line, mode[Left].col, color );
  289.    s_output( itoa( mode[Left].mode+1, temp, 10 ), mode[Left].line, mode[Left].col,
  290.              color);
  291. }
  292.  
  293.  
  294. /*
  295.  * Name:    show_para
  296.  * Date:    January 20, 1992
  297.  */
  298. void show_para( void )
  299. {
  300. char temp[10];
  301.  
  302.    s_output( "   ", mode[Para].line, mode[Para].col, color );
  303.    s_output( itoa( mode[Para].mode+1, temp, 10 ), mode[Para].line, mode[Para].col,
  304.              color);
  305. }
  306.  
  307.  
  308. /*
  309.  * Name:    show_right
  310.  * Date:    January 20, 1992
  311.  */
  312. void show_right( void )
  313. {
  314. char temp[10];
  315.  
  316.    s_output( "   ", mode[Right].line, mode[Right].col, color );
  317.    s_output( itoa(mode[Right].mode+1,temp,10), mode[Right].line, mode[Right].col,
  318.              color);
  319. }
  320.  
  321.  
  322. /*
  323.  * Name:    show_cursor_size
  324.  * Date:    January 20, 1992
  325.  */
  326. void show_cursor_size( void )
  327. {
  328. char *p[] = {
  329.    "Small Insert Cursor",
  330.    "Big Insert Cursor  ",
  331. };
  332.  
  333.    s_output( p[mode[Size].mode], mode[Size].line, mode[Size].col, color );
  334. }
  335.  
  336.  
  337. /*
  338.  * Name:    show_backup_mode
  339.  * Date:    January 20, 1992
  340.  */
  341. void show_backup_mode( void )
  342. {
  343. char *p[] = {
  344.    "No .bak files    ",
  345.    "Create .bak files"
  346. };
  347.  
  348.    s_output( p[mode[Backup].mode], mode[Backup].line, mode[Backup].col, color );
  349. }
  350.  
  351.  
  352. /*
  353.  * Name:    show_backup_mode
  354.  * Date:    January 20, 1992
  355.  */
  356. void show_ruler_mode( void )
  357. {
  358. char *p[] = {
  359.    "No ruler  ",
  360.    "Show ruler"
  361. };
  362.  
  363.    s_output( p[mode[Ruler].mode], mode[Ruler].line, mode[Ruler].col, color );
  364. }
  365.  
  366.  
  367. /*
  368.  * Name:    show_date_style
  369.  * Date:    June 5, 1992
  370.  */
  371. void show_date_style( void )
  372. {
  373. char *p[] = {
  374.    "MM_DD_YY  ",
  375.    "DD_MM_YY  ",
  376.    "YY_MM_DD  ",
  377.    "MM_DD_YYYY",
  378.    "DD_MM_YYYY",
  379.    "YYYY_MM_DD",
  380. };
  381.  
  382.    s_output( p[mode[Date].mode], mode[Date].line, mode[Date].col, color );
  383. }
  384.  
  385.  
  386. /*
  387.  * Name:    show_time_style
  388.  * Date:    June 5, 1992
  389.  */
  390. void show_time_style( void )
  391. {
  392. char *p[] = {
  393.    "12_HOUR",
  394.    "24_HOUR"
  395. };
  396.  
  397.    s_output( p[mode[Time].mode], mode[Time].line, mode[Time].col, color );
  398. }
  399.  
  400.  
  401. /*
  402.  * Name:    change_modes
  403.  * Date:    July 21, 1991
  404.  * Notes:   Real workhorse function of the utility.  Get a key and then
  405.  *          figure out what to do with it.
  406.  */
  407. void change_modes( void )
  408. {
  409. int c;
  410. int m;
  411. int new_field;
  412.  
  413.    m = 0;
  414.    xygoto( mode[m].col, mode[m].line );
  415.    color = 112;
  416.    (*mode[m].show_me)();
  417.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  418.       c = getkey( );
  419.       new_field = FALSE;
  420.       color = 112;
  421.       switch (c) {
  422.          case RTURN :
  423.          case DOWN  :
  424.             color = 7;
  425.             (*mode[m].show_me)();
  426.             ++m;
  427.             if (m > 18)
  428.                m = 0;
  429.             new_field = TRUE;
  430.             break;
  431.          case UP    :
  432.             color = 7;
  433.             (*mode[m].show_me)();
  434.             --m;
  435.             if (m < 0)
  436.                m = 18;
  437.             new_field = TRUE;
  438.             break;
  439.          case LEFT  :
  440.             switch (m) {
  441.                case Ins     :
  442.                case Ind     :
  443.                case Write_Z :
  444.                case Smart   :
  445.                case Trim    :
  446.                case Eol     :
  447.                case Size    :
  448.                case Backup  :
  449.                case Ruler   :
  450.                case Time    :
  451.                   mode[m].mode = !mode[m].mode;
  452.                   break;
  453.                case PTAB    :
  454.                case LTAB    :
  455.                   if (mode[m].mode > 1)
  456.                      --mode[m].mode;
  457.                   else
  458.                      mode[m].mode = 1040 / 2;
  459.                   break;
  460.                case WW      :
  461.                   --mode[m].mode;
  462.                   if (mode[m].mode < 0)
  463.                      mode[m].mode = 2;
  464.                   break;
  465.                case Date    :
  466.                   --mode[m].mode;
  467.                   if (mode[m].mode < 0)
  468.                      mode[m].mode = 5;
  469.                   break;
  470.                case Crlf    :
  471.                   if (mode[m].mode == CRLF)
  472.                      mode[m].mode = LF;
  473.                   else
  474.                      mode[m].mode = CRLF;
  475.                   break;
  476.                case Left    :
  477.                case Para    :
  478.                   if (mode[m].mode > 0)
  479.                      --mode[m].mode;
  480.                   else
  481.                      mode[m].mode = mode[Right].mode - 1;
  482.                   break;
  483.                case Right   :
  484.                   if (mode[m].mode > mode[Left].mode + 1 &&
  485.                       mode[m].mode > mode[Para].mode + 1)
  486.                      --mode[m].mode;
  487.                   else
  488.                      mode[m].mode = 1040;
  489.                   break;
  490.                case Initcase   :
  491.                   if (mode[m].mode == 1)
  492.                      mode[m].mode = 2;
  493.                   else
  494.                      mode[m].mode = 1;
  495.                   break;
  496.             }
  497.             (*mode[m].show_me)();
  498.             break;
  499.          case RIGHT :
  500.             switch (m) {
  501.                case Ins     :
  502.                case Ind     :
  503.                case Write_Z :
  504.                case Smart   :
  505.                case Trim    :
  506.                case Eol     :
  507.                case Size    :
  508.                case Backup  :
  509.                case Ruler   :
  510.                case Time    :
  511.                   mode[m].mode = !mode[m].mode;
  512.                   break;
  513.                case PTAB     :
  514.                case LTAB     :
  515.                   if (mode[m].mode < 1040 / 2)
  516.                     ++mode[m].mode;
  517.                   else
  518.                      mode[m].mode = 1;
  519.                   break;
  520.                case WW      :
  521.                   ++mode[m].mode;
  522.                   if (mode[m].mode > 2)
  523.                      mode[m].mode = 0;
  524.                   break;
  525.                case Date    :
  526.                   ++mode[m].mode;
  527.                   if (mode[m].mode > 5)
  528.                      mode[m].mode = 0;
  529.                   break;
  530.                case Crlf    :
  531.                   if (mode[m].mode == CRLF)
  532.                      mode[m].mode = LF;
  533.                   else
  534.                      mode[m].mode = CRLF;
  535.                   break;
  536.                case Left    :
  537.                case Para    :
  538.                   if (mode[m].mode < mode[Right].mode)
  539.                      ++mode[m].mode;
  540.                   else
  541.                      mode[m].mode = 0;
  542.                   break;
  543.                case Right   :
  544.                   if (mode[m].mode < 1038)
  545.                      ++mode[m].mode;
  546.                   else {
  547.                      if (mode[Left].mode < mode[Para].mode)
  548.                         mode[m].mode = mode[Para].mode + 1;
  549.                      else
  550.                         mode[m].mode = mode[Left].mode + 1;
  551.                   }
  552.                   break;
  553.                case Initcase   :
  554.                   if (mode[m].mode == 1)
  555.                      mode[m].mode = 2;
  556.                   else
  557.                      mode[m].mode = 1;
  558.                   break;
  559.             }
  560.             (*mode[m].show_me)();
  561.             break;
  562.       }
  563.       if (new_field) {
  564.          color = 112;
  565.          (*mode[m].show_me)();
  566.          xygoto( mode[m].col, mode[m].line );
  567.       }
  568.    }
  569.  
  570.    /*
  571.     * write changes to "tde.exe" if user presses F10.
  572.     */
  573.    if (c == F10) {
  574.       in_modes.insert        = mode[Ins].mode;
  575.       in_modes.indent        = mode[Ind].mode;
  576.       in_modes.ptab_size     = mode[PTAB].mode;
  577.       in_modes.ltab_size     = mode[LTAB].mode;
  578.       in_modes.smart_tab     = mode[Smart].mode;
  579.       in_modes.control_z     = mode[Write_Z].mode;
  580.       in_modes.crlf          = mode[Crlf].mode;
  581.       in_modes.trailing      = mode[Trim].mode;
  582.       in_modes.show_eol      = mode[Eol].mode;
  583.       in_modes.word_wrap     = mode[WW].mode;
  584.       in_modes.left_margin   = mode[Left].mode;
  585.       in_modes.parg_margin   = mode[Para].mode;
  586.       in_modes.right_margin  = mode[Right].mode;
  587.       in_modes.cursor_size   = mode[Size].mode;
  588.       in_modes.do_backups    = mode[Backup].mode;
  589.       in_modes.ruler         = mode[Ruler].mode;
  590.       in_modes.date_style    = mode[Date].mode;
  591.       in_modes.time_style    = mode[Time].mode;
  592.       in_modes.search_case   = mode[Initcase].mode;
  593.       fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  594.       fwrite( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  595.    }
  596.    cls( );
  597. }
  598.